home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / libsrc~1.z / libsrc~1 / strcmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-28  |  557 b   |  31 lines

  1. #include "lib.h"
  2.  
  3. /*
  4.  * strcmp - compare string s1 to s2
  5.  */
  6.  
  7. int                /* <0 for <, 0 for ==, >0 for > */
  8. strcmp(s1, s2)
  9. _CONST register char *s1;
  10. _CONST register char *s2;
  11. {
  12.     while (*s1 != '\0' && *s1 == *s2) {
  13.         s1++;
  14.         s2++;
  15.     }
  16.  
  17.     /*
  18.      * The following case analysis is necessary so that characters
  19.      * which look negative collate low against normal characters but
  20.      * high against the end-of-string NUL.
  21.      */
  22.     if (*s1 == '\0' && *s2 == '\0')
  23.         return(0);
  24.     else if (*s1 == '\0')
  25.         return(-1);
  26.     else if (*s2 == '\0')
  27.         return(1);
  28.     else
  29.         return(*s1 - *s2);
  30. }
  31.